﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Security/Security.master" AutoEventWireup="true"
    EnableEventValidation="true" CodeBehind="GroupManagement.aspx.cs" Inherits="_00365.Security.GroupManagement" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
    <div style="width: 93%;">
        <asp:UpdatePanel ID="updPanel" runat="server">
            <ContentTemplate>
                <asp:Button ID="btnNewGroup" runat="server" Text="Novo Grupo" OnClick="btnNewGroup_Click" />
                <asp:Panel ID="pnlPopupNewGroup" runat="server" CssClass="popUpDialog">
                    <div id="divPopupTitle" runat="server" class="popUpDialogTitle head box" style="cursor: move;">
                        <asp:Label ID="lblNewGroupDialogTitle" Text="Incluir Novo Grupo" runat="server" Style="cursor: move;" />
                        <div class="alignright">
                            <asp:ImageButton ID="btnCloseNewGroup" runat="server" ImageUrl="~/images/popup_close.png"
                                AlternateText="Fechar" OnClick="btnCloseNewGroup_Click" /></div>
                        <div class="clear">
                        </div>
                    </div>
                    <div class="clear">
                    </div>
                    <div class="popUpDialogContent">
                        <div class="content">
                            <p>
                                Nome:
                                <asp:TextBox ID="txtGroupName" runat="server" CssClass=""></asp:TextBox>
                            </p>
                        </div>
                        <div class="content">
                            <p>
                                Ativo:
                                <asp:RadioButtonList ID="rdlActive" runat="server" RepeatLayout="Flow">
                                    <asp:ListItem Text="Sim" Value="True" Selected="True"></asp:ListItem>
                                    <asp:ListItem Text="Não" Value="False"></asp:ListItem>
                                </asp:RadioButtonList>
                            </p>
                        </div>
                        <div class="alignright">
                            <asp:Button ID="btnSaveNewGroup" runat="server" Text="Salvar" OnClick="btnSaveNewGroup_Click" />
                        </div>
                        <div class="clear">
                        </div>
                    </div>
                </asp:Panel>
                <a href="#" id="lnkShowModal" runat="server" style="display: none;">x</a>
                <ajaxToolkit:ModalPopupExtender ID="popAddEditGroup" runat="server" BackgroundCssClass="modalBackground"
                    CancelControlID="btnCloseNewGroup" PopupControlID="pnlPopupNewGroup" PopupDragHandleControlID="divPopupTitle"
                    TargetControlID="lnkShowModal">
                </ajaxToolkit:ModalPopupExtender>
                <asp:HiddenField ID="hidFlagAddEdit" runat="server" />
                <asp:HiddenField ID="hidGroupID" runat="server" />
                <asp:GridView ID="grdGroups" runat="server" AutoGenerateColumns="False" Width="550px"
                    OnRowCommand="grdGroups_RowCommand" ViewStateMode="Enabled" AllowPaging="true"
                    OnPageIndexChanged="grdGroups_PageIndexChanged" OnPageIndexChanging="grdGroups_PageIndexChanging"
                    PageSize="10">
                    <Columns>
                        <asp:BoundField DataField="Name" HeaderText="Nome" ReadOnly="True">
                            <ItemStyle Width="300px" />
                        </asp:BoundField>
                        <asp:CheckBoxField DataField="Active" HeaderText="Ativo" ReadOnly="True">
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:CheckBoxField>
                        <asp:TemplateField HeaderText="Ações">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnEditGroup" runat="server" CommandName="EditGroup" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                    <asp:Image ImageUrl="~/images/edit.png" runat="server" ToolTip="Alterar" AlternateText="Alterar" />
                                </asp:LinkButton>
                                &nbsp;
                                <asp:LinkButton ID="btnRemoveGroup" runat="server" CommandName="DeleteGroup" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                    <asp:Image ImageUrl="~/images/delete.png" runat="server" ToolTip="Excluir"  AlternateText="Excluir" />
                                </asp:LinkButton>
                                &nbsp;
                                <asp:LinkButton ID="btnViewGroupUsers" runat="server" CommandName="ViewUsers" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                    <asp:Image ImageUrl="~/images/group.png" runat="server" ToolTip="Ver usuários associados" AlternateText="Usuários"/>
                                </asp:LinkButton>
                                &nbsp;
                                <asp:LinkButton ID="btnEditPermissions" runat="server" CommandName="Permissions"
                                    CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                    <asp:Image ImageUrl="~/images/lock.png" runat="server" ToolTip="Editar Permissões do Grupo" AlternateText="Permissões" />
                                </asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="150px" />
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle CssClass="head" />
                    <PagerStyle CssClass="head" HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <%--popup Groups->Users--%>
        <asp:Panel ID="pnlPopUpGroupUsers" runat="server" CssClass="popUpDialog">
            <div id="divPopupGroupUsersTitle" runat="server" class="popUpDialogTitle head box"
                style="cursor: move;">
                <asp:Label ID="lblPopupGroupUsers" Text="Gerenciar Usuários do Grupo" runat="server"
                    Style="cursor: move;" />
                <div class="alignright">
                    <asp:ImageButton ID="btnClosePopupGroupUsers" runat="server" ImageUrl="~/images/popup_close.png"
                        AlternateText="Fechar" OnClick="btnCloseNewGroup_Click" /></div>
                <div class="clear">
                </div>
            </div>
            <div class="clear">
            </div>
            <asp:UpdatePanel ID="updPanelGroupUsers" runat="server">
                <ContentTemplate>
                    <div class="popUpDialogContent" style="width: 98%; margin: 2px; padding: 3px;">
                        <div class="alignleft" style="margin-right: 10px; width: 330px; height: 300px; overflow: auto;">
                            <asp:GridView ID="grdGroupUsers" runat="server" AutoGenerateColumns="False" Width="305px"
                                ViewStateMode="Enabled" OnRowCommand="grdGroupUsers_RowCommand">
                                <EmptyDataTemplate>
                                    <div class="box" style="width: 250px;">
                                        Não há usuários associados a este grupo</div>
                                </EmptyDataTemplate>
                                <Columns>
                                    <asp:BoundField DataField="UserName" HeaderText="Login (E-mail)" ReadOnly="True">
                                        <ItemStyle Width="200px" />
                                    </asp:BoundField>
                                    <asp:CheckBoxField DataField="Active" HeaderText="Ativo" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Center" Width="50px" />
                                    </asp:CheckBoxField>
                                    <asp:TemplateField HeaderText="Ações">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <asp:LinkButton ID="btnRemoveUserFromGroup" runat="server" CommandName="Remove" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                                <asp:Image ID="Image2" ImageUrl="~/images/right.png" runat="server" AlternateText="Remover"
                                                    ToolTip="Remover usuário do grupo" />
                                            </asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <HeaderStyle CssClass="head" />
                            </asp:GridView>
                        </div>
                        <div class="alignleft" style="margin-left: 10px; width: 330px; height: 300px; overflow: auto;">
                            <asp:GridView ID="grdAvailableUsers" runat="server" AutoGenerateColumns="False" Width="310px"
                                ViewStateMode="Enabled" OnRowCommand="grdAvailableUsers_RowCommand">
                                <EmptyDataTemplate>
                                    <div class="box" style="width: 250px;">
                                        Não existem usuários disponíveis</div>
                                </EmptyDataTemplate>
                                <Columns>
                                    <asp:TemplateField HeaderText="Ações">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <asp:LinkButton ID="btnAddUserToGroup" runat="server" CommandName="Add" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                                <asp:Image ID="Image2" ImageUrl="~/images/left.png" runat="server" AlternateText="Incluir"
                                                    ToolTip="Incluir usuário no grupo" />
                                            </asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="UserName" HeaderText="Login (E-mail)" ReadOnly="True">
                                        <ItemStyle Width="200px" />
                                    </asp:BoundField>
                                    <asp:CheckBoxField DataField="Active" HeaderText="Ativo" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Center" Width="50px" />
                                    </asp:CheckBoxField>
                                </Columns>
                                <HeaderStyle CssClass="head" />
                            </asp:GridView>
                        </div>
                        <div class="clear">
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </asp:Panel>
        <a href="#" id="lnkShowPopupGroupUsers" runat="server" style="display: none;">x</a>
        <ajaxToolkit:ModalPopupExtender ID="popGroupUsers" runat="server" BackgroundCssClass="modalBackground"
            CancelControlID="lnkShowPopupGroupUsers" OkControlID="lnkShowPopupGroupUsers"
            PopupControlID="pnlPopUpGroupUsers" PopupDragHandleControlID="divPopupGroupUsersTitle"
            ViewStateMode="Disabled" TargetControlID="lnkShowPopupGroupUsers">
        </ajaxToolkit:ModalPopupExtender>
        <%--popup Delete message--%>
        <asp:Panel ID="pnlDeleteMsg" runat="server" CssClass="popUpDialog">
            <div id="divMsgDeleteTitle" runat="server" class="popUpDialogTitle head box" style="cursor: move;">
                <asp:Label ID="Label1" Text="Excluir Grupo de Usuários" runat="server" Style="cursor: move;" />
                <div class="alignright">
                    <asp:ImageButton ID="btnCloseDeleteMsg" runat="server" ImageUrl="~/images/popup_close.png"
                        AlternateText="Fechar" OnClick="btnCloseNewGroup_Click" ToolTip="Fechar" /></div>
                <div class="clear">
                </div>
            </div>
            <div class="content">
                <p style="text-align: center;">
                    <asp:Label ID="lblDeleteMsg" Text="Deseja realmente excluir o grupo?" runat="server"></asp:Label>
                </p>
            </div>
            <div class="content" style="text-align: center; margin-top: 25px;">
                <asp:UpdatePanel ID="updMsgBox" runat="server">
                    <ContentTemplate>
                        <asp:Button ID="btnDeleteMsgYes" runat="server" Text="Sim" OnClick="btnDeleteMsgYes_Click" />
                        &nbsp;
                        <asp:Button ID="btnDeleteMsgNo" runat="server" Text="Não" OnClick="btnDeleteMsgNo_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
            <div class="clear">
            </div>
        </asp:Panel>
        <a href="#" id="lnkShowPopupDeleteMsg" runat="server" style="display: none;">x</a>
        <ajaxToolkit:ModalPopupExtender ID="popDeleteMsg" runat="server" BackgroundCssClass="modalBackground"
            CancelControlID="lnkShowPopupDeleteMsg" OkControlID="lnkShowPopupDeleteMsg" PopupControlID="pnlDeleteMsg"
            PopupDragHandleControlID="divMsgDeleteTitle" ViewStateMode="Disabled" TargetControlID="lnkShowPopupDeleteMsg">
        </ajaxToolkit:ModalPopupExtender>
        <%-- popup Permissoes --%>
        <asp:Panel ID="pnlPermissoesGrupo" runat="server" CssClass="popUpDialog">
            <div id="divPermissionsTitle" runat="server" class="popUpDialogTitle head box" style="cursor: move;">
                <asp:Label ID="Label2" Text="Gerenciar Permissões do Grupo" runat="server" Style="cursor: move;" />
                <div class="alignright">
                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/popup_close.png"
                        AlternateText="Fechar" OnClick="btnCloseNewGroup_Click" /></div>
                <div class="clear">
                </div>
            </div>
            <div class="clear">
            </div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <div class="alignleft" style="margin-right: 10px; width: 330px; height: 300px; overflow: auto;">
                        <asp:GridView ID="grdGranted" runat="server" AutoGenerateColumns="False" Width="305px"
                            ViewStateMode="Enabled" OnRowCommand="grdGranted_RowCommand">
                            <EmptyDataTemplate>
                                <div class="box" style="width: 250px;">
                                    Não há permissões associadas a este grupo</div>
                            </EmptyDataTemplate>
                            <Columns>
                                <asp:BoundField DataField="Description" HeaderText="Permissões atribuídas" ReadOnly="True">
                                    <ItemStyle Width="250px" />
                                </asp:BoundField>
                                <asp:TemplateField HeaderText="Ações">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="btnRevokePermission" runat="server" CommandName="Revoke" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                            <asp:Image ID="Image2" ImageUrl="~/images/right.png" runat="server" AlternateText="Remover"
                                                ToolTip="Remover permissão do grupo" />
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <HeaderStyle CssClass="head" />
                        </asp:GridView>
                    </div>
                    <div class="alignleft" style="margin-right: 10px; width: 330px; height: 300px; overflow: auto;">
                        <asp:GridView ID="grdAvailableFeatures" runat="server" AutoGenerateColumns="False" Width="305px"
                            ViewStateMode="Enabled" OnRowCommand="grdAvailableFeatures_RowCommand">
                            <EmptyDataTemplate>
                                <div class="box" style="width: 250px;">
                                    Não há permissões disponíveis atualmente</div>
                            </EmptyDataTemplate>
                            <Columns>
                                <asp:TemplateField HeaderText="Ações">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="btnGrantPermission" runat="server" CommandName="Grant" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "Id") %>'>
                                            <asp:Image ID="Image2" ImageUrl="~/images/left.png" runat="server" AlternateText="Atribuir"
                                                ToolTip="Atribuir permissão ao grupo" />
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="Description" HeaderText="Permissões disponíveis" ReadOnly="True">
                                    <ItemStyle Width="250px" />
                                </asp:BoundField>
                            </Columns>
                            <HeaderStyle CssClass="head" />
                        </asp:GridView>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </asp:Panel>
        <a href="#" id="lnkShowPopupPermissions" runat="server" style="display: none;">x</a>
        <ajaxToolkit:ModalPopupExtender ID="popPermissions" runat="server" BackgroundCssClass="modalBackground"
            CancelControlID="lnkShowPopupPermissions" OkControlID="lnkShowPopupPermissions"
            PopupControlID="pnlPermissoesGrupo" PopupDragHandleControlID="divPermissionsTitle"
            ViewStateMode="Disabled" TargetControlID="lnkShowPopupPermissions">
        </ajaxToolkit:ModalPopupExtender>
    </div>
</asp:Content>
